package com.zgjkhis.modules.system.service.mapper;

import com.zgjkhis.common.mapper.CoreMapper;
import com.zgjkhis.modules.system.domain.CptStore;
import com.zgjkhis.modules.system.domain.vo.CptStoreVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Author yzq
 * @Description 合作门店
 * @Date 2021/6/23 9:48
 * @Param
 * @return
 **/
@Repository
public interface CptStoreMapper extends CoreMapper<CptStore> {


    /**
     * 根据id查询合作药房
     * @param cptStore
     * @return
     */
    @Select("<script>select * from his_cpt_store where (store_id=#{cpt.storeId} and cpt_store_id=#{cpt.cptStoreId}) or (store_id=#{cpt.cptStoreId} and cpt_store_id=#{cpt.storeId})</script>")
    CptStore getOneBystoreId(@Param("cpt") CptStore cptStore);

    /**
     * 根据id查询合作药房
     * @param storeId
     * @return
     */
    @Select("<script>select t.*,s.store_name as storeName,k.store_name as cptStoreName from (select * from his_cpt_store where store_id =#{storeId} or cpt_store_id=#{storeId}) t\n" +
            "left join his_store s on t.store_id=s.id\n" +
            "left join his_store k on t.cpt_store_id=k.id</script>")
    List<CptStoreVO> getCptStore(@Param("storeId") String storeId);
}
